package com.ywgt.controller;

import com.ywgt.service.GoodsProductService;
import com.ywgt.service.GoodsService;
import com.ywgt.service.OrderService;
import com.ywgt.service.UserService;
import com.ywgt.util.ResponseUtil;
import io.swagger.annotations.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/admin/dashboard")
@ApiModel("后台管理界面")
public class DashboardController {

    @Autowired
    UserService userService;

    @Autowired
    GoodsService goodsService;

    @Autowired
    OrderService orderService;

    @Autowired
    GoodsProductService goodsProductService;

    @GetMapping
    public Object dashboard(){
        Map<String,Integer> data=new HashMap<>();
        int userTotal = userService.count();
        int goodsTotal = goodsService.count();
        int productTotal = goodsProductService.count();
        int orderTotal = orderService.count();
        data.put("userTotal", userTotal);
        data.put("goodsTotal", goodsTotal);
        data.put("productTotal", productTotal);
        data.put("orderTotal", orderTotal);
        return ResponseUtil.ok(data);
    }
}
